package com.zzty.springmybatis.service.impl;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zzty.springmybatis.DAO.UserDAO;
import com.zzty.springmybatis.entity.User;
import com.zzty.springmybatis.service.UserService;

@Service
public class UserServiceImpl implements UserService {

	@Autowired
	UserDAO userDao;

	public User getUserByName(String name) {
		return userDao.getUserByName(name);
	}

	public void addUser(User user) {
		userDao.addUser(user);

	}

	public boolean login(User user) {
		String name = user.getName();
		User finalUser = getUserByName(name);
		if (user.getPassword().equals(finalUser.getPassword())) {
			return true;
		} else {
			return false;
		}
	}

	public void updateUser(String email,String phone,String sex,Integer clazzId,String disname,String name) {
		userDao.updateUser(email,phone,sex,clazzId,disname,name);
	}

	public void updatePwd(String password, String name) {
		userDao.updatePwd(password, name);
	}

	public void changeImg(String name) {
		userDao.changeImg(name);
	}

	public String findPwd(String name, String email) {

		return userDao.findPwd(name, email);
	}

	public List<Integer> searchStuIdByClazzID(Integer classId) {
		return userDao.searchStuIdByclazzId(classId);
	}

	public User selectUserInfo(User user) {
		return userDao.selectUserInfo(user);
	}
	
	public String searchPwdByName(String name){
		return userDao.searchPwdByName(name);
	}
	
	public String getDisnameById(Integer id){
		return userDao.getDisnameById(id);
	}

	@Override
	public List<User> searchStuByClazzID(Integer clazzId) {
		
		return userDao.searchStuByclazzId(clazzId);
	}
}
